<template>
	<view class="c-wrap" v-if="config">
		<ice-header :account="userInfo && userInfo.nickname"></ice-header>
		<view style="margin: 0 25rpx;">
			<u-swiper :list="config.banner" height="314rpx" radius="20rpx" bgColor="#070707"></u-swiper>
			<!-- <u--image @click="goGame" mode="aspectFill" :showLoading="true" src="../../static/bn.png" radius="20rpx" width="700rpx" height="314rpx" ></u--image> -->
			<view style="margin-top: 20rpx;border: 1px solid #252525;border-radius: 6rpx;">
				<u-row-notice :text="config.notice" fontSize="26rpx" bgColor="#060911" color="#ffffff">
					<view slot="icon" class="u-flex-row u-flex-xy-center" style="width: 60rpx;height: 60rpx">
						<image class="notice-icon" src="../../static/tz@2x.png"></image>
					</view>
				</u-row-notice>
			</view>
			<view style="margin: 20rpx 30rpx;flex-wrap: wrap;" class="u-flex-row u-flex-y-center u-flex-around">
				<view class="game-item" v-for="(game,idx) in gameList.list" :index="idx"  @click="goGame(game)">
					<u--image class="game-img"
						mode="aspectFit" :showLoading="true" :src="game.image" radius="0rpx" width="200rpx"
						height="200rpx"></u--image>
				</view>
			</view>
		</view>
		
		<ice-tabbar :index="0"></ice-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: null,
				nodes: [],
				notice: '共创链游Dapp就即将上线,敬请期待',
				config: null,
				gameList: [],
			}
		},
		async onLoad(e) {
			this.getConfig()
			await uni.$ice.checkLogin()
			this.getUserInfo()
			this.getGameList();
		},
		async onShow() {
			if (this.userInfo) {
				let address = await uni.$ice.getAddress();
				console.log(address)
				if (this.userInfo.username != address) {
					uni.removeStorageSync("token")
					await uni.$ice.checkLogin()
					this.getUserInfo()
				}
				this.getGameList();
			}
		},
		methods: {
			goGame(item) {
				location.href = item.link
			},
			getConfig() {
				uni.$ice.post('index/config', {}, false).then(res => {
					this.config = res.data
				}).catch(err => {

				})
			},
			getUserInfo() {
				let tmp = uni.getStorageSync('userInfo')
				if (tmp) {
					this.userInfo = JSON.parse(tmp)
				}
				uni.$ice.post('user/index', {}, false).then(res => {
					uni.setStorageSync('userInfo', JSON.stringify(res.data));
					this.userInfo = res.data
					if (this.userInfo.username != uni.$ice.walletAddress) {
						uni.removeStorageSync("token")
						location.reload();
					}
					uni.stopPullDownRefresh()

				}).catch(err => {

				})
			},
			getGameList() {
				uni.$ice.post('user/game', {}, false).then(res => {
					this.gameList = res.data;
				}).catch(err => {})
			},
		}

	}
</script>

<style scoped>
	page {
		background-color: transparent;
	}
	.game-item{
		width: 230rpx;
		height: 230rpx;
		background-image: url('../../static/game-bg.png');
		background-size: 100% 100%;
		margin-bottom: 35rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.game-img {
		
	}

	.notice-icon {
		width: 36rpx;
		height: 31rpx;
	}
</style>